<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/laypublic.jsp" %>
<%@ include file="../include/vueComponent.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>营销策划详情</title>
</head>
<link rel="stylesheet" href="${ctx}/resources/vue-element-lib/detail.css">
<body>
<div id="app">
    <div class="layui-tab layui-tab-brief" lay-filter="xqxx-tab-all">
        <ul class="layui-tab-title">
            <li id="tbglId" class="layui-this" lay-id="0">营销策划详情</li>
            <li id="zgysId" lay-id="1">历史审批信息</li>
        </ul>
        <div class="layui-tab-right">
            <c:if test="${isAuditFlag eq '1'}">
                <template v-if="layId==0">
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" @click="save(0)">保存
                    </button>
                    <button type="button" class="layui-btn layui-btn-radius" @click="save(1)">提交</button>
                </template>
            </c:if>
            <c:if test="${auditTabFlag eq '1'}">
                <template>
                    <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" @click="audit(0)">
                        不同意
                    </button>
                    <button type="button" class="layui-btn layui-btn-radius" @click="audit(1)">同意</button>
                </template>
            </c:if>
        </div>
        <div class="layui-tab-content" style="height: 100px;">
            <div class="layui-tab-item layui-show">

                <div class="container">
                    <el-form ref="formRef" label-width="180px" label-suffix="："
                             label-position="left">
                        <%--项目基础信息--%>
                        <div class="title">
                            <h3>项目基础信息</h3>
                        </div>
                        <el-row>
                            <x-col>
                                <el-form-item label="项目名称">
                                    <span>{{projectInfo.proName}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="项目编码">
                                    <span>{{projectInfo.proCode}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="项目业态">
                                    <span>{{projectInfo.proFormat}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="策划书编码">
                                    <span>{{projectInfo.id}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="所属公司">
                                    <span>{{projectInfo.compName}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="营销经理">
                                    <span>{{projectInfo.staffName}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="政府内部评审阶段" :rules="[{ required: true}]">
                                    <x-input v-model="proSell.internalReviewStage" name="政府内部评审阶段"/>
                                </el-form-item>
                            </x-col>

                        </el-row>
                        <%--营销班子--%>
                        <div class="title">
                            <h3>营销班子</h3>
                        </div>
                        <div class="unit">
                            <div class="unit_add">
                                <button class="layui-btn layuiadmin-btn-admin" type="button"
                                        @click="addMarketingTeamTableData">
                                    <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>添加营销班子
                                </button>
                            </div>
                            <div class="unit_center">
                                <div class="unit_img">
                                    <div class="item" v-for="(item,index) in marketingTeamTableData" :key="index"
                                         v-if="marketingTeamTableData.length>1">
                                        <img src="${ctx}/resources/images/del.png" alt=""
                                             @click="delMarketingTeamTableData(index)">
                                    </div>
                                </div>
                                <el-table :data="marketingTeamTableData" style="width: 100%" border>
                                    <el-table-column label="姓名" align="center">
                                        <template slot-scope="scope">
                                            <el-select v-model="scope.row.name" filterable placeholder="请选择"
                                                       @change="selPersonnel($event,scope.$index)"
                                                       remote :remote-method="remoteMethod">
                                                <el-option v-for="item in personnel" :key="item.id"
                                                           :label="item.staffName"
                                                           :value="item.id"></el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="职务" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.position" :disabled="true"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="备注" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.remarks" placeholder="请输入备注"></el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                        <%--业主信息--%>
                        <div class="title">
                            <h3>业主信息</h3>
                        </div>
                        <%--业主单位名称 单位性质 内部关系--%>
                        <el-row>
                            <x-col>
                                <el-form-item label="业主单位名称" :rules="[{ required: true}]">
                                    <el-select v-model="proSell.ownerOrgSguid" filterable style="width: 100%"
                                               placeholder="请选择">
                                        <el-option v-for="item in owner" :key="item.id" :label="item.coopName"
                                                   :value="item.id"></el-option>
                                    </el-select>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="单位性质" :rules="[{ required: true}]">
                                    <x-input v-model="proSell.orgNature" name="单位性质"/>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <%--内部关系--%>
                        <el-row>
                            <x-col>
                                <el-form-item label="内部关系" :rules="[{ required: true}]">
                                    <x-input v-model="proSell.innerRelationship" name="内部关系"/>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <%--竞争对手分析--%>
                        <div class="title">
                            <h3>竞争对手分析</h3>
                        </div>
                        <div class="unit">
                            <div class="unit_add">
                                <button class="layui-btn layuiadmin-btn-admin" type="button"
                                        @click="addOpponentExplain">
                                    <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>添加竞争对手
                                </button>
                            </div>
                            <div class="unit_center">
                                <div class="unit_img">
                                    <div class="item" v-for="(item,index) in opponentExplain" :key="index"
                                         v-if="opponentExplain.length>1">
                                        <img src="${ctx}/resources/images/del.png" alt=""
                                             @click="delOpponentExplain(index)">
                                    </div>
                                </div>
                                <el-table :data="opponentExplain" style="width: 100%" border>
                                    <el-table-column label="竞争对手名称" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.competitor" placeholder="竞争对手名称"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="基本情况" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.basic" placeholder="基本情况"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="优势" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.advantage" placeholder="优势"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="劣势" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.inferior" placeholder="劣势"></el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                        <%--自身分析--%>
                        <div class="title">
                            <h3>自身分析</h3>
                        </div>
                        <%-- 竞争优势--%>
                        <el-row>
                            <x-col position="full">
                                <el-form-item label="竞争优势" :rules="[{ required: true}]">
                                    <x-input v-model="proSell.selfGoodness" type="textarea" :rows="4"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <%--竞争劣势--%>
                        <el-row>
                            <x-col position="full">
                                <el-form-item label="竞争劣势" :rules="[{ required: true}]">
                                    <x-input v-model="proSell.selfRisk" type="textarea" :rows="4"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <%--营销策划--%>
                        <div class="title">
                            <h3>营销策划</h3>
                        </div>
                        <%--项目所处阶段--%>
                        <el-row>
                            <x-col position="full">
                                <el-form-item label="项目所处阶段">
                                    <span>{{proSell.proStage}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <%--工作目标--%>
                        <el-row>
                            <x-col position="full">
                                <el-form-item label="工作目标" :rules="[{ required: true}]">
                                    <x-input v-model="proSell.pushOver" type="textarea" :rows="4"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <div class="unit" style="margin-top: 30px">
                            <div class="unit_add">
                                <button class="layui-btn layuiadmin-btn-admin" type="button" data-type="add"
                                        @click="addFocusArr">
                                    <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>添加工作重点
                                </button>
                            </div>
                            <div class="unit_center">
                                <div class="unit_img">
                                    <div class="item" v-for="(item,index) in focusArr" :key="index"
                                         v-if="focusArr.length>1">
                                        <img src="${ctx}/resources/images/del.png" alt="" @click="delFocusArr(index)">
                                    </div>
                                </div>
                                <el-table :data="focusArr" style="width: 100%" border>
                                    <el-table-column label="重点" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.emphasis" placeholder="重点"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="工作现状" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.actuality" placeholder="工作现状"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="需总部支持的方面" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.support" placeholder="需总部支持的方面"></el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                        <div class="unit">
                            <div class="unit_add">
                                <button class="layui-btn layuiadmin-btn-admin" type="button" data-type="add"
                                        @click="addDifficultyArr">
                                    <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>添加工作难点
                                </button>
                            </div>
                            <div class="unit_center">
                                <div class="unit_img">
                                    <div class="item" v-for="(item,index) in difficultyArr" :key="index"
                                         v-if="difficultyArr.length>1">
                                        <img src="${ctx}/resources/images/del.png" alt=""
                                             @click="delDifficultyArr(index)">
                                    </div>
                                </div>
                                <el-table :data="difficultyArr" style="width: 100%" border>
                                    <el-table-column label="难点" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.difficult" placeholder="难点"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="工作现状" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.actuality" placeholder="工作现状"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="需总部支持的方面" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.support" placeholder="需总部支持的方面"></el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>
                        <div class="title">
                            <h3>预计营销费用</h3>
                        </div>
                        <el-row>
                            <x-col position="full">
                                <el-form-item label="营销费用总预算(万元)">
                                    <span>{{sumMarketingMoney||0}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <div class="unit">
                            <div class="unit_add">
                                <button class="layui-btn layuiadmin-btn-admin" type="button" data-type="add"
                                        @click="addMarketingList">
                                    <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>添加营销费用
                                </button>
                            </div>
                            <div class="unit_center">
                                <div class="unit_img">
                                    <div class="item" v-for="(item,index) in marketingList" :key="index"
                                         v-if="marketingList.length>1">
                                        <img src="${ctx}/resources/images/del.png" alt=""
                                             @click="delMarketingList(index)">
                                    </div>
                                </div>

                                <el-table :data="marketingList" style="width: 100%" border>
                                    <el-table-column label="费用类型" align="center">
                                        <template slot-scope="scope">
                                            <el-select v-model="scope.row.types" filterable
                                                       placeholder="请选择费用类型"
                                                       @change="marketingListSel($event,scope.$index)">
                                                <el-option v-for="item in typesArr" :key="item.code" :label="item.name"
                                                           :value="item.code"></el-option>
                                            </el-select>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="费用金额" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.costMoney" type="number" min="0"
                                                      @input="changeMoney"
                                                      placeholder="费用金额"></el-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="预计时间" align="center">
                                        <template slot-scope="scope">
                                            <el-date-picker v-model="scope.row.willOccurDate" type="date"
                                                            value-format="yyyy-MM-dd"
                                                            placeholder="选择日期"></el-date-picker>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="备注" align="center">
                                        <template slot-scope="scope">
                                            <el-input v-model="scope.row.remarks" placeholder="备注"></el-input>
                                        </template>
                                    </el-table-column>
                                </el-table>
                            </div>
                        </div>

                        <div class="title">
                            <h3>项目附件信息</h3>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">附件：</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" type="button" id="9-upload-more">上传</button>
                                    <div class="layui-upload-list" id="9-upload-more-list">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <c:if test="${auditTabFlag eq '1'}">
                            <div class="title">
                                <h3>审批信息</h3>
                            </div>
                            <%@ include file="process/process-audit.jsp" %>
                        </c:if>
                    </el-form>
                </div>

            </div>
            <div class="layui-tab-item">
                <%@ include file="process/process-history.jsp" %>
            </div>
        </div>
    </div>
</div>
<script src="${ctx}/resources/vue-element-lib/jquery.js"></script>
<script>
    var fileArr = [];
    <%--var id = "${id}";--%>
    var staticPath = '${fileHttpPre}';
    layui.config({
        base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set', 'upload', 'table', 'transfer', 'laydate', 'element', 'layer'], function () {
        var $ = layui.$
            , upload = layui.upload
            , table = layui.table
            , element = layui.element
            , layer = layui.layer;

        //选项卡切换监听
        element.on('tab(xqxx-tab-all)', function (data) {
            var layId = $(this).attr('lay-id');
            vm.$data.layId = layId;
            if (layId === "0") {

            } else if (layId === "1") {
                loadTable(layId);
            } else if (layId === "2") {

            }
        });

        function loadTable(layId) {
            // 表单
            table.render({
                elem: '#lay-lsspxx-create-manage'
                , url: basePath + '/historyProcess/list?proCode=${proCode}'
                , cols: [[
                    {
                        field: 'startTime', title: '发起时间', width: 145, width: 155, templet: function (d) {
                            return layui.util.toDateString(d.startTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {field: 'startRealName', title: '发起人', width: 145}
                    , {field: 'proFlowType', title: '审批阶段', width: 145}
                    , {field: 'proFlowNode', title: '审批节点', width: 145}
                    , {
                        field: 'dealTime', title: '审批日期', width: 155, templet: function (d) {
                            return layui.util.toDateString(d.dealTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {field: 'dealName', title: '审批人', width: 160}
                    , {
                        field: 'state', title: '审批状态'
                    }
                    , {
                        title: '操作', width: 140, align: 'center', fixed: 'right', templet: function (d) {
                            var optStr = "";
                            optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>查看</a>';
                            return optStr;
                        }
                    }
                ]]
                , page: true
                , limit: 10
            });

            // 监听操作列
            table.on('tool(lay-lsspxx-create-manage)', function (obj) {
                var data = obj.data;
                if (obj.event === 'view') {//查看
                    parent.layui.index.openTabsPage(basePath + '/historyProcess/toDetail?processId=' + data.processId, '历史流程信息 > 详情');
                }
            });
        }

        //多文件列表示例
        upload.render({
            elem: '#9-upload-more',
            url: basePath + '/contractInfo/uploadAtt/',
            data: {
                types: 9
            },
            multiple: true,
            accept: 'file',
            acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf',
            before: function (obj) { //obj参数包含的信息
                layer.load(); //上传loading
            },
            done: function (res) {
                //如果上传失败
                if (res.code > 0) {

                    layer.closeAll('loading'); //关闭loading
                    return layer.msg(res.msg, {icon: 7});
                }
                //上传完毕
                if (res.entity != null && res.entity.length > 0) {
                    fileArr.push(res.entity[0])
                    for (var i in res.entity) {
                        var contractInfo = res.entity[i];
                        var arr = contractInfo.split("|");
                        var imgSrc = "";
                        var suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1, arr[1].length);
                        if (suffix == 'jpg' || suffix == 'png') {
                            imgSrc = "${fileHttpPre}/" + arr[3];
                        } else {
                            imgSrc = "${ctx}/resources/images/" + suffix + ".jpg";
                        }
                        $('#9-upload-more-list')
                            .append('<div class="layui-upload-img-div" id="upload_img_' + arr[2] + '"><img src="' + imgSrc + '" title="'
                                + arr[1] + '" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\'' + "${fileHttpPre}"
                                + arr[3] + '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
                                + arr[2] + '\')";>删除</a></div><p>' + arr[1] + '</p><input type="hidden" value="'
                                + contractInfo + '" id="fileAtt_' + arr[2] + '" name="fileAtts" ></input></div> ');
                    }
                }
            }
            ,
            allDone: function (obj) { //当文件全部被提交后，才触发
                layer.closeAll('loading'); //关闭loading
            },
            error: function () {
                layer.closeAll('loading'); //关闭loading
                //上传失败
                layer.msg("上传失败，请稍后再试~", {icon: 7});
            }
        });
    });

    //删除文件
    function del(index) {
        layui.$("#fileAtt_" + index).remove();
        layui.$("#upload_img_" + index).remove();
        fileArr.map((el, idx) => {
            if (el.split('|')[2] == index) {
                fileArr.splice(idx, 1)
            }
        })
    }

    //根据url查看文件
    function showImg(url) {
        var openWin = window.open(url, '', 'left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
    }

    /*核心*/
    var vm = new Vue({
        el: '#app',
        data() {
            return {
                layId: '0',
                processId: '',
                procNodeList: [],
                tempNodeList: [],
                auditMsg: '',//审批意见


                proSell: {},
                projectInfo: {
                    proName: '',//项目名称
                    proCode: '',//项目编码
                    proFormat: '',//项目业态
                    compName: '',//所属公司
                    staffName: '',//营销经理
                },
                marketingTeamTableData: [],//营销班子  name 姓名 postion 职务 note 备注
                marketingList: [],//预计营销费用
                opponentExplain: [],//竞争对手
                focusArr: [],//重点
                difficultyArr: [],//难点
                owner: [],//业主单位
                sumMarketingMoney: 0,
                typesArr: [],//费用类型
                code: '',
                allPersonnel: [],//所有人员
                personnel: [],
            }
        },
        created() {
            let that = this;
            that.id = "${id}";
            that.code = "${proCode}";
            that.processId = "${processId}";
            that.queryCoopInfo();
            that.queryPersonnel();
            that.costTypes();

            that.queryProcessList()
        },
        mounted() {

        },
        methods: {
            remoteMethod(query) {
                let that = this;
                let arr = [];
                if (query !== "") {
                    that.allPersonnel.map(el => {
                        if (el.staffName.indexOf(query) != -1) {
                            arr.push(el)
                        }
                    })
                    that.personnel = arr.slice(0, 50);
                } else {
                    arr = that.allPersonnel;
                    that.personnel = arr.slice(0, 50);
                }
            },
            //详情
            queryDetail() {
                let that = this;
                $.ajax({
                    type: 'post',
                    url: basePath + '/proSell/queryDetail',  //请求数据接口
                    data: {
                        code: that.code
                    },
                    success: function (result) {
                        that.projectInfo = result.projectInfo;
                        that.sumMarketingMoney = result.sumMarketingMoney;
                        that.proSell = result.proSell;
                        that.marketingList = result.marketingList;//预计营销费用
                        if (that.marketingList.length > 0) {
                            that.marketingList.map(el => {
                                el.willOccurDate = that.formatTime(el.willOccurDate)
                            })
                        }
                        that.marketingTeamTableData = result.proSell.marketingTeamTableData ? JSON.parse(result.proSell.marketingTeamTableData) : [];//营销班子
                        if (that.marketingTeamTableData.length > 0) {
                            that.marketingTeamTableData.map(el => {
                                that.allPersonnel.map(el1 => {
                                    if (el.name == el1.id) {
                                        that.personnel.push(el1)
                                    }
                                })
                            })
                        }
                        that.personnel = that.deDuplication(that.personnel, 'id')
                        if (fileArr.length == 0) {
                            that.showFile(result.fileAtt)
                        }
                        //竞争对手
                        that.proSell.opponentExplain = that.proSell.opponentExplain ? JSON.parse(that.proSell.opponentExplain) : []
                        that.proSell.keyPoints = that.proSell.keyPoints ? JSON.parse(that.proSell.keyPoints) : []
                        that.opponentExplain = that.proSell.opponentExplain && that.proSell.opponentExplain.length > 0 ? that.proSell.opponentExplain : [];
                        //重点
                        that.focusArr = that.proSell.keyPoints && that.proSell.keyPoints.length > 0 ? that.proSell.keyPoints[0] : [];
                        //难点
                        that.difficultyArr = that.proSell.keyPoints && that.proSell.keyPoints.length > 0 ? that.proSell.keyPoints[1] : [];

                    }
                });
            },
            deDuplication(arr, key) {
                var result = [];
                var obj = {};
                for (var i = 0; i < arr.length; i++) {
                    if (!obj[arr[i][key]]) {
                        result.push(arr[i]);
                        obj[arr[i][key]] = true;
                    }
                }
                return result;
            },
            // 格式化时间
            formatTime(time) {
                let date = new Date(time);
                date.getFullYear()
                let year = date.getFullYear();
                let month = (date.getMonth() + 1) > 9 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1);
                let day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate();
                let timer = year + '-' + month + '-' + day
                return timer
            },
            showFile(fileList) {
                if (fileList && fileList.length > 0) {
                    fileArr = fileList;
                    for (let i in fileList) {
                        let contractInfo = fileList[i];
                        let arr = contractInfo.split("|");
                        let imgSrc = "";
                        let suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1, arr[1].length);
                        if (suffix == 'jpg' || suffix == 'png') {
                            imgSrc = "${fileHttpPre}/" + arr[3];
                        } else {
                            imgSrc = "${ctx}/resources/images/" + suffix + ".jpg";
                        }
                        $('#' + arr[0] + '-upload-more-list')
                            .append('<div class="layui-upload-img-div" id="upload_img_' + arr[2] + '"><img src="' + imgSrc + '" title="'
                                + arr[1] + '" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\'' + "${fileHttpPre}"
                                + arr[3] + '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
                                + arr[2] + '\')";>删除</a></div><p>' + arr[1] + '</p><input type="hidden" value="'
                                + contractInfo + '" id="fileAtt_' + arr[2] + '" name="fileAtts" ></input></div> ');
                    }
                }
            },
            // 选择
            marketingListSel(data, index) {
                let that = this;
                let arr = [];
                that.marketingList.map(el => {
                    if (el.types == data) {
                        arr.push(el.types);
                    }
                })
                if (arr.length > 1) {
                    that.marketingList[index].types = '';
                    return that.error('请重新选择费用类型');
                }
            },

            changeMoney(v) {
                var sum = 0;
                this.marketingList.map(el => {
                    sum += Number(el.costMoney);
                })
                this.sumMarketingMoney = sum;
                this.sumMarketingMoney = Number(this.sumMarketingMoney).toFixed(2)
            },
            // 业主单位
            queryCoopInfo() {
                let that = this;
                $.ajax({
                    type: 'post',
                    url: basePath + '/proSell/queryCoopInfo',  //请求数据接口
                    data: {},
                    success: function (result) {
                        that.owner = result;
                    }
                });
            },
            //获取所有人
            queryPersonnel() {
                let that = this;
                const loading = this.$loading({
                    lock: true,
                    text: '拼命加载中',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                $.ajax({
                    type: 'post',
                    url: basePath + '/proSell/queryPersonnel',  //请求数据接口
                    data: {},
                    success: function (result) {
                        if (result && result.length > 0) {
                            let arr = result
                            that.allPersonnel = result;
                            that.personnel = arr.slice(0, 50);
                        }
                        loading.close();
                        that.queryDetail()
                    }
                });
            },
            costTypes() {
                let that = this;
                $.ajax({
                    type: 'post',
                    url: basePath + '/proSell/costTypes',  //请求数据接口
                    data: {},
                    success: function (result) {
                        that.typesArr = result
                    }
                });
            },
            selPersonnel(e, index) {
                this.personnel.map(el => {
                    if (el.id == e) {
                        this.marketingTeamTableData[index].position = el.jobname;
                    }
                })
            },
            //添加营销班子
            addMarketingTeamTableData() {
                let obj = {
                    name: '',
                    position: '',
                    remarks: '',
                }
                this.marketingTeamTableData.push(obj);
            },
            //删除营销班子
            delMarketingTeamTableData(index) {
                this.marketingTeamTableData.splice(index, 1)
            },
            //添加竞争对手
            addOpponentExplain() {
                let obj = {
                    competitor: "",//竞争对手
                    basic: "",//基本情况
                    advantage: "",//优势
                    inferior: ""//劣势
                }
                this.opponentExplain.push(obj);
            },
            //删除竞争对手
            delOpponentExplain(index) {
                this.opponentExplain.splice(index, 1)
            },
            //添加重点
            addFocusArr() {
                let obj = {
                    emphasis: '',// 重点
                    actuality: '',//工作现状
                    support: '',//需总部支持的方面
                }
                this.focusArr.push(obj);
            },
            //删除重点
            delFocusArr(index) {
                this.focusArr.splice(index, 1)
            },
            //添加难点
            addDifficultyArr() {
                let obj = {
                    difficult: '',// 难点
                    actuality: '',//工作现状
                    support: '',//需总部支持的方面
                }
                this.difficultyArr.push(obj);
            },
            //添加重点
            delDifficultyArr(index) {
                this.difficultyArr.splice(index, 1)
            },
            //添加预计营销费用
            addMarketingList() {
                // typesArr
                let that = this;
                if (that.marketingList.length < that.typesArr.length) {
                    let obj = {
                        types: '',// 费用类型
                        costMoney: '',//费用金额
                        willOccurDate: '',//预计时间
                        remarks: '',//备注
                        proSellId: '',
                    }
                    that.marketingList.push(obj);
                } else {
                    that.$message.error('不可添加');
                }
                // types 费用类型 costMoney 费用金额 willOccurDate 预计时间 remarks 备注

            },
            //删除预计营销费用
            delMarketingList(index) {
                this.marketingList.splice(index, 1)
            },
            error(text) {
                this.$message({
                    message: text,
                    type: 'warning'
                });
            },
            //保存
            save(type) {
                let that = this;
                if (!that.proSell.internalReviewStage) return that.error('请输入政府内部评审阶段');
                if (!that.proSell.ownerOrgSguid) return that.error('请选择业主单位');
                if (!that.proSell.orgNature) return that.error('请输入单位性质');
                if (!that.proSell.innerRelationship) return that.error('请输入内部关系');
                if (!that.proSell.selfGoodness) return that.error('请输入竞争优势');
                if (!that.proSell.selfRisk) return that.error('请输入竞争劣势');
                if (!that.proSell.pushOver) return that.error('请输入工作目标');
                if (that.opponentExplain.length == 0) return that.error('请添加竞争对手分析');
                for (let i = 0; i < that.opponentExplain.length; i++) {
                    if (!that.opponentExplain[i].basic) return that.error('请输入竞争对手分析-基本情况');
                    if (!that.opponentExplain[i].inferior) return that.error('请选择竞争对手分析-劣势');
                }
                if (that.marketingList.length == 0) return that.error('请添加预计营销费用');
                for (let i = 0; i < that.marketingList.length; i++) {
                    if (!that.marketingList[i].types) return that.error('请选择预计营销费用-费用类型');
                    if (!that.marketingList[i].costMoney) return that.error('请输入预计营销费用-费用金额');
                    if (!that.marketingList[i].willOccurDate) return that.error('请选择预计营销费用-预计时间');
                }
                if (that.focusArr.length == 0) return that.error('请添加工作重点');
                for (let i = 0; i < that.focusArr.length; i++) {
                    if (!that.focusArr[i].emphasis) return that.error('请输入工作重点-重点');
                    if (!that.focusArr[i].actuality) return that.error('请输入工作重点-工作现状');
                }
                if (that.difficultyArr.length == 0) return that.error('请添加工作难点');
                for (let i = 0; i < that.difficultyArr.length; i++) {
                    if (!that.difficultyArr[i].difficult) return that.error('请输入工作难点-难点');
                    if (!that.difficultyArr[i].actuality) return that.error('请输入工作难点-工作现状');
                }
                that.proSell.keyPoints = [];
                that.proSell.opponentExplain = [];
                that.proSell.marketingTeamTableData = [];
                that.proSell.opponentExplain = that.opponentExplain && that.opponentExplain.length > 0 ? that.opponentExplain : [];//竞争对手
                that.proSell.marketingTeamTableData = that.marketingTeamTableData && that.marketingTeamTableData.length > 0 ? that.marketingTeamTableData : [];//营销班子
                that.proSell.keyPoints.push(that.focusArr && that.focusArr.length > 0 ? that.focusArr : [])
                that.proSell.keyPoints.push(that.difficultyArr && that.difficultyArr.length > 0 ? that.difficultyArr : [])
                let obj = {
                    "projectInfo": that.projectInfo,
                    "proSell": that.proSell,
                    "marketingList": that.marketingList,
                    "fileAtt": fileArr && fileArr.length > 0 ? fileArr : [],//附件信息
                }
                if (obj.marketingList.length > 0) {
                    obj.marketingList.map(el => {
                        el.proSellId = obj.proSell.id
                    })
                }
                let str = JSON.stringify(obj).replace(/\"/g, '\\"')
                $.ajax({
                    type: "POST", //提交方式
                    url: "${ctx}/proSell/save",//路径

                    data: {
                        projectSellDto: str,
                        code: that.code,
                        identifying: type + '',
                    }, //数据，这里使用的是Json格式进行传输
                    success: function (result) {//返回数据根据结果进行相应的处理
                        if (result.success) {
                            that.$message({
                                message: result.msg,
                                type: 'success'
                            });
                            setTimeout(function () {
                                // 刷新首页
                                let index = window.parent.layui.admin.tabsPage.index
                                if (index == null) {
                                    window.close();
                                } else {
                                    var iframe = window.parent.layui.admin.tabsBody((index - 1)).find(".layadmin-iframe");
                                    iframe[0].contentWindow.location.reload();
                                    top.layui.admin.closeThisTabs(); // 关闭当前标签页
                                }
                            }, 3000);
                        } else {
                            that.$message.error(result.msg);
                            that.queryDetail()
                        }
                    }
                });
            },

            queryProcessList() {
                let that = this;
                $.ajax({
                    type: 'post',
                    url: basePath + '/historyProcess/processList',  //请求数据接口
                    data: {processId: that.processId},
                    success: function (result) {
                        if (result.success) {
                            that.procNodeList = result.entity.procNodeList;
                            that.tempNodeList = result.entity.tempNodeList;
                        }
                    }
                });
            },
            audit(status) {
                let that = this;
                $.ajax({
                    type: 'post',
                    url: basePath + '/setupPro/auditProcess',  //请求数据接口
                    async: false,
                    data: {
                        id: that.id,
                        processId: that.processId,
                        status: status,
                        auditMsg: that.auditMsg
                    },
                    success: function (result) {
                        if (result.success) {
                            that.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                            setTimeout(function () {
                                // 刷新首页
                                let index = window.parent.layui.admin.tabsPage.index
                                if (index == null) {
                                    window.close();
                                } else {
                                    var iframe = window.parent.layui.admin.tabsBody((index - 1)).find(".layadmin-iframe");
                                    iframe[0].contentWindow.location.reload();
                                    top.layui.admin.closeThisTabs(); // 关闭当前标签页
                                }
                            }, 3000);
                        } else {
                            that.$message.error('保存失败');
                        }
                    }
                });
            }
        }
    })
</script>
</body>
</html>

